package yifeng.thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 验证多线程产生的差错
 * @author Administrator
 *
 */
public class TT {
//	private static int i = 0;
	
	private static int[] a = new int[10];
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ExecutorService es = Executors.newFixedThreadPool(10);
		final CountDownLatch latch = new CountDownLatch(10);
		
		for(int j = 0; j < 10; j++){
			es.execute(new Runnable(){
				@Override
				public void run() {
					for(int m = 0; m < 10000; m++)
						a[0]++;
					
					latch.countDown();
				}
			});
		}

		
		try {
			latch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		es.shutdown();
		System.out.println(a[0]);
	}

}
